#include <iostream>
#include <vector>
using namespace std;
using ll=long long;
int main() {

	int n;
	ll nRet=0;
	cin>>n;
	vector<ll> vecArr(n+1);
	vector<ll> f(n+1),g(n+1);
	for(int i=1;i<=n;++i){
		cin>>vecArr[i];
	}
	f[1]=vecArr[1];
	nRet=f[1];
	for(int i=2;i<=n;++i){
		f[i]=g[i-1]+vecArr[i];
		g[i]=max(f[i-1],g[i-1]);
		nRet=max(nRet,max(f[i],g[i]));
	}
	cout<<nRet<<endl;
	
	return 0;
}
